import {defineConfig, loadEnv} from 'vite'
import {resolve} from "path"
import vue from '@vitejs/plugin-vue'


export default ({mode}) => {
    const config = loadEnv(mode, './')
    return defineConfig({
            plugins: [
                vue(),


            ],
            css: {
                preprocessorOptions: {
                    scss: {
                        api: 'modern-compiler',
                        additionalData: `@use "@/styles/variables.scss" as *;`, // 导出全局变量和 mixin
                    },
                }
            },
            define: {
                'process.env': {}
            },

            base: config.VITE_BASE_URL,
            resolve: {
                alias: {
                    "@": resolve(__dirname, "./src"),
                    "components": resolve(__dirname, "./src/components"),
                    "styles": resolve(__dirname, "./src/styles"),
                    "utils": resolve(__dirname, "./src/utils"),
                }
            },
            // build: {
            //     rollupOptions: {
            //         manualChunks(id) {
            //             console.log("id-------------", id);
            //         }
            //     }
            // },
            server: {
                proxy: {
                    "/startApi": {
                        changeOrigin: true,
                        ws: true,
                        secure: false, // 忽略证书错误
                        target: "http://localhost:8097"
                        // target: "https://218.78.131.248:38080"
                    }
                }
            }
        }
    )
}
